<div class="container">
  <section>
    <h2>
      <a ui-sref="app.projects"><i class="fa fa-angle-left"></i> 返回</a> 添加项目工程
    </h2>

    <form class="form" name="form" ng-submit="create(project)" novalidate>
      <br/>
      <fieldset>
        <div class="form-group" ng-class="{ 'has-success': form.title.$valid,
                                              'has-error': form.title.$invalid && submitted }">
          <label for="project_name">*项目名称</label>
          <input type="text" class="form-control" placeholder="填写项目名称" id="project_name" required
                 ng-model="project.name" name="name"/>

          <p class="help-block" ng-show="form.name.$error.required">
            <span class="text-danger"> 项目名称 为必填项目</span>
          </p>
        </div>

        <div class="form-group" ng-class="{ 'has-success': form.type.$valid,
                                              'has-error': form.type.$invalid && submitted }">
          <label for="type">*工程类型</label>
          <select class="form-control" id="'type" ng-model="project.type" required name="type">
            <option value="">----请选择工程类型-----</option>
            <option value="家装项目">家装项目</option>
            <option value="公建项目">公建项目</option>
          </select>

          <p class="help-block" ng-show="form.type.$error.required">
            <span class="text-danger"> 工程类型 为必填项目</span>
          </p>
        </div>

        <div class="form-group" ng-class="{ 'has-success': form.leaderId.$valid,
                                              'has-error': form.leaderId.$invalid && submitted }">
          <label for="leaderId">*负责人</label>
          <select class="form-control" id="'leaderId" ng-model="project.leader" required name="leaderId"
                  ng-options="user._id as user.name group by user.department.name for user in users"
            >
            <option value="">----请选择负责人-----</option>
          </select>

          <p class="help-block" ng-show="form.leaderId.$error.required">
            <span class="text-danger"> 负责人 为必填项目</span>
          </p>
        </div>

        <div class="form-group" ng-class="{ 'has-success': form.joiners.$valid,
                                              'has-error': form.joiners.$invalid && submitted }">
          <label for="joiners">*参加人员</label>
          <ui-select multiple ng-model="project.joiners" theme="bootstrap" name="joiners" id="joiners">
            <ui-select-match placeholder="请选择参加人员...">{{$item.name}}</ui-select-match>
            <ui-select-choices group-by="departmentGroup" repeat="user._id as user in users | propsFilter: {name: $select.search}">
              <div ng-bind-html="user.name | highlight: $select.search"></div>
            </ui-select-choices>
          </ui-select>
          <p class="help-block" ng-show="form.joiners.$error.required">
            <span class="text-danger"> 参加人员 为必填项目</span>
          </p>
        </div>

        <div class="form-group" ng-class="{ 'has-success': form.start_date.$valid,
                                              'has-error': form.start_date.$invalid && submitted }">
          <label for="start_date">*开始日期</label>
          <input type="text" id="start_date" class="form-control" datepicker-popup="yyyy-MM-dd" is-open="opened" ng-focus="opened = true" name="start_date" ng-model="project.start_date" datepicker-options="dateOptions" ng-required="true" show-weeks="false" show-button-bar="false" toggle-weeks-text="周" current-text="今天" clear-text="清除" close-text="确定" />
          <p class="help-block" ng-show="form.start_date.$error.required">
            <span class="text-danger"> 开始日期 为必填项目</span>
          </p>
        </div>

        <div class="form-group" ng-class="{ 'has-success': form.progress.$valid,
                                              'has-error': form.progress.$invalid && submitted }">
          <label for="progress">*工程进度</label>
          <select class="form-control" id="'progress" ng-model="project.progress" required name="progress">
            <option value="">----请选择工程进度-----</option>
            <option value="招标">招标</option>
            <option value="前期">前期</option>
            <option value="中期">中期</option>
            <option value="售后">售后</option>
          </select>

          <p class="help-block" ng-show="form.progress.$error.required">
            <span class="text-danger"> 工程进度 为必填项目</span>
          </p>
        </div>

        <button class="btn btn-primary btn-login" ng-disabled="form.$invalid" type="submit">
          添加
        </button>
      </fieldset>
    </form>
  </section>
</div>
